﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Find maximal increasing sequence</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
     <div id="js-console"></div>
	<script src="scripts/js-console.js"></script>
	<script>
	    var arr = [1, 2, 5, 3, 6, 3, 5, 6, 7,3, 8, 9];
	    var count = 1;
	    var max = 1;
	    var start = 0;
	    for (var i = 0; i < arr.length; i++) {
	        if (arr[i] + 1 == arr[i+1]) {
	            count++;
	            if (count > max) {
	                max = count;
	                start = arr[i+1];
	            }
	        }
	        else {
	            count = 1;
	        }
	    }
	    if (max == 1) {
	        jsConsole.writeLine("This sequence doesn`t have a maximal sequence of increasing elements. ");
	    }
	    else {
	        jsConsole.writeLine("The maximal sequence of increasing elements is: " + max + " -> ")
	        for (var i = max; i > 0; i--) {
	            jsConsole.write((start-i+1) + " ");
	        }
	    }
    </script>
</body>
</html>
